package sunset.lucifer.ko.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import sunset.lucifer.ko.model.User;
import sunset.lucifer.ko.service.UserService;
import sunset.lucifer.ko.util.JsonUtil;

/**
 * 用户信息操作接口
 * Created by Administrator on 2016/11/18.
 */
@Controller
@Scope("prototype")
public class UserInsController extends BaseController {
    @Autowired
    @Qualifier("userService")
    private UserService userService;

    /**
     * 用户信息注册接口
     * 请求数据格式：
     * {"username":"",
     * "password":"",
     * "mobile":""}
     *
     * @param jsonCode 请求信息json
     * @return jsonStr 发送信息json
     */
    @RequestMapping(value = "user/insertUser.json", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
    @ResponseBody
    public String insertUser(@RequestBody String jsonCode) {
        System.out.println(jsonCode);
        User user = JsonUtil.changeJsonToObject(jsonCode, User.class);
        if (user == null) {
            return super.requestErrorResult();
        }
        System.out.println(user);
        int value = userService.insertRecord(user);
        if (value == 0) {
            return super.successResult();
        } else {
            return super.insErrorResult(value);
        }
    }

}
